﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;

namespace ZingFrameworkCore.Common.Cache.Cookie
{
    public class HttpContextCookie
    {

        public static void Write(string strName, string strValue)
        {
            HttpContext.Current.Response.Cookies.Append(strName, strName);
        }

        public static void Write(string strName, string strValue, int expires)
        {
            HttpContext.Current.Response.Cookies.Append(strName, strValue, new CookieOptions()
            {
                Expires = DateTimeOffset.Now.AddMinutes(expires)
            });
        }

        public static string Get(string strName)
        {
            if (HttpContext.Current != null && HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
            {
                return HttpContext.Current.Request.Cookies[strName];
            }
            return "";
        }

        public static void Remove(string strName)
        {
            HttpContext.Current.Response.Cookies.Delete(strName);
        }

    }
}
